<?php

/**
 * Created on 7 mai 2011
 *  * @author Samy Deghou(deghou@polytech.unice.fr ; deghou@embl.de)
 * 		   Stephan Beisken (beisken@ebi.ac.uk)
 * 		   Luis Felipe De Figueiredo (ldpf@ebi.ac.uk)
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
class MSsignal implements iCRUD {
    /*
     * Attributes
     */

    private $_msSignalID;
    private $_mz;
    private $_ionizationType;
    private $_intensity;
    private $_derivatization;
    private $_comments;
    private $_moleculeID;
    private $_spectrumID;


    /*
     * Constructor
     */

    public function MSsignal($mz, $ionizationType, $intensity, $derivatization, $comments, $moleculeID, $spectrumID, $msSignalID, $msSignalID=-1) {
        $this->_mz = $mz;
        $this->_ionizationType = $ionizationType;
        $this->_intensity = $intensity;
        $this->_derivatization = $derivatization;
        $this->_comments = $comments;
        $this->_moleculeID = $moleculeID;
        $this->_spectrumID = $spectrumID;
        $this->_msSignalID = $msSignalID;
    }

    /*
     * Accessors
     */

    public function getmoleculeID() {
        return $this->_moleculeID;
    }

    public function getMsSignalID() {
        return $this->_msSignalID;
    }

    public function getMZ() {
        return $this->_mz;
    }

    public function getIonizationType() {
        return $this->_ionizationType;
    }

                
    public function getIntensity() {
        return $this->_Intensity;
    }

    public function getDerivatization() {
        return $this->_derivatization;
    }

    public function getComments() {
        return $this->_comments;
    }

    public function getSpectrumID() {
        return $this->_spectrumID;
    }

    /*
     * Modifiers
     */

    public function setmoleculeID($param) {
        $this->_moleculeID = $param;
    }

    public function setMsSignalID($param) {
        $this->_msSignalID = $param;
    }

    public function setMZ($param) {
        $this->_mz = $param;
    }

    public function setIonizationType($param) {
        $this->_ionizationType = $param;
    }

    public function setIntensity($param) {
        $this->_intensity = $param;
    }

    public function setDerivatization($param) {
        $this->_derivatization = $param;
    }

    public function setComments($param) {
        $this->_comments = $param;
    }

    public function setSpectrumID($param) {
        $this->_spectruumID = $param;
    }

    /*
     * CRUD
     */

    /**
     * Put an object in the database
     */
    public function create() {
        Database::connect();
        if ($this->_msSignalID != -1)
            die("Unable to create, still existing !");
        else {
            $query = "INSERT INTO `MS_SIGNAL` values (NULL,'" .
                    $this->_mz . "','" .
                    $this->_ionisationType . "','" .
                    $this->_intensity . "','" .
                    $this->_derivatization . "','" .
                    $this->_comments . "','" .
                    $this->_moleculeID . "','" .
                    $this->_spectrumID . "')";
            mysql_query($query) or die(mysql_error());
            $this->_idSujet = mysql_insert_id();
        }
        Database::disconnect();
    }

    /**
     * Read an object from the database
     */
    public static function read($key) {
        Database::connect();
        $query = "SELECT * FROM MS_SIGNAL WHERE ms_signal_id = '" . $key . "'";
        $ans = mysql_fetch_assoc(mysql_query($query));
        extract($ans);
        Database::disconnect();
        return new MSsignal($mz, $ionization_type, $intensity, $derivatization,
                $comments, $molecule_id, $spectrum_id, $ms_signal_id, $ms_signal_id);
        Database::disconnect();
    }

    /**
     * Update an object from the database
     */
    public function update() {
        Database::connect();
        $query = "UPDATE `MS_SIGNAL` SET mz='" .
                $this->_mz . "', ionization_type='" .
                $this->_ionizationType . "', intensity='" .
                $this->_intensity . "', derivatization='" .
                $this->_derivatization . "', comments='" .
                $this->_comments . "', molecule_id='" .
                $this->_moleculeID . "', spectrum_id='" .
                $this->_spectrumID . "' WHERE ms_signal_id='" .
                $this->_msSignalID . "'";
        mysql_query($query) or die(mysql_error());
        Database::disconnect();
    }

    /**
     * Delete an object from the database
     */
    public function delete() {
        Database::connect();
        $query = "DELETE FROM `MS_SIGNAL` WHERE ms_signal_id='" .
                $this->_msSignalID . "'";
        mysql_query($query) or die(mysql_error());
        Database::disconnect();
    }

}
?>
